<?php

namespace Home\Model;

use Think\Model\RelationModel;

class MixModel extends RelationModel {
    protected $_link = array(
        'Goods'=>array(
            'mapping_type'      => self::MANY_TO_MANY,
            'class_name'        => 'Goods',
            'foreign_key'       =>  'mix_id',
            'relation_foreign_key'  =>  'goods_id',
            'relation_table'    =>  'ecm_mix_goods',
            ),
        );

    /**
     * 取得某自由搭配的信息
     * @param   int     $mix_id       自由搭配
     * @param   bool    $mix_info  返回的信息
     */	
	function get_info($mix_id)
	{
        $mix_info = $this->alias('mix')->field('mix.*, store.store_name')->where("mix_id = ".$mix_id)->join('LEFT JOIN '.C('DB_PREFIX').'store store ON store.store_id=mix.store_id')->find();

		$goods_info = M('Goods')->where('goods_id='.$mix_info['nav_goods_id'])->find();
        if($goods_info)
        {
			$mix_info['goods_info'] = $goods_info;
		}
		return $mix_info;
	}

}

?>
